package org.leyi.shop.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.leyi.shop.common.exception.BusinessException;
import org.leyi.shop.common.response.BaseResponse;
import org.leyi.shop.common.response.EnumResponse;
import org.leyi.shop.model.request.UserRequest;
import org.leyi.shop.model.vo.SafetyUser;
import org.leyi.shop.service.SellerService;
import org.leyi.shop.util.BaseResponseUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("seller")
public class SellerController {
    @Resource
    private SellerService sellerService;

    /**
     *
     * description: 商家登录
     * @param userRequest
     * @param request
     * @return BaseResponse<SafetyUser>
     * @author  lenovo
     * create 2024/5/9-16:41
     */
    @PostMapping("/login")
    public BaseResponse<SafetyUser> login(@RequestBody UserRequest userRequest, HttpServletRequest request)
    {
        if(userRequest==null)
        {
            throw new BusinessException(EnumResponse.PARAMETER_ERR);
        }
        return BaseResponseUtils.success(sellerService.login(userRequest.getUserAccount(), userRequest.getUserPassword(), request),"登录成功");
    }

    /**
     *
     * description: 商家获取盈利
     * @param userAccount 用账户来获取
     * @return BaseResponse<Double>
     * @author  lenovo
     * create 2024/5/9-16:44
     */
    @GetMapping("profit/{userAccount}")
    public BaseResponse<Double> getProfit(@PathVariable String userAccount)
    {
        return BaseResponseUtils.success(sellerService.getProfit(userAccount),"获取盈利成功");
    }
    /**
     * 其余接口参见用户接口
     */
}
